package com.essc.controller;

import com.essc.pojo.Goods;
import com.essc.pojo.User;
import com.essc.service.AdminService;
import com.essc.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Controller
@RequestMapping("/admin")//区别于其他模块
public class AdminController {

    @Autowired
    AdminService adminService;

    //查找所有用户——————————postman测试通过
    @RequestMapping("/findAllUser")
    @ResponseBody
    public JsonResult findAllUserAdmin(){
        JsonResult jsonResult = adminService.findAllUserInfoAdmin();
        return jsonResult;
    }


    //新增用户————————————postman测试通过
    @PostMapping("/addUser")
    @ResponseBody
    public JsonResult addUserAdmin(@RequestBody User user){
        JsonResult jsonResult = adminService.addUserAdmin(user);
        return jsonResult;
    }

    //修改用户信息——————————————postman测试通过
    @PostMapping("/updateUserMessage")
    @ResponseBody
    public JsonResult updateUserInfoAdmin(@RequestBody User user){
        JsonResult jsonResult = adminService.updateUserMessageAdmin(user);
        return jsonResult;
    }

    //删除用户信息，参数id是从页面传回的，与页面的参数名一致————postman测试通过
    @PostMapping("/deleteUserInfo/{uid}")
    @ResponseBody
    public JsonResult deleteUserInfoAdmin(@PathVariable("uid") Integer uid){
        return adminService.deleteUserInfoByUidAdmin(uid);
    }

    //批量删除用户信息，根据用户id删除
    @PostMapping("/deleteUserInfoByIds")
    @ResponseBody
    public JsonResult deleteUserInfoByIdsAdmin(@RequestBody Integer[] ids){
        return adminService.deleteUserInfoByUidArrayAdmin(ids);
    }

    //分页操作————根据pageNun和pageSize返回相应的数据——————————postman测试通过
    @GetMapping("/findUserInfoByPage/{pageNum}/{pageSize}")
    @ResponseBody
    public JsonResult findUserInfoByPageAdmin
                        (@PathVariable("pageNum") Integer pageNum,
                         @PathVariable("pageSize") Integer pageSize){
        return adminService.findUserInfoByPageAdmin(pageNum,pageSize);
    }

    //============ 俊龙 7.10新增 ===================

    //管理员-用户管理-根据id查找用户信息
    @GetMapping("/findUserInfoById/{uid}")
    @ResponseBody
    public JsonResult findUserInfoByIdAdmin(@PathVariable("uid") Integer uid){
        return adminService.findUserInfoByUidAdmin(uid);
    }

    //管理员-商品管理-查找所有商品信息
    @GetMapping("findAllGoodsInfo/{pageNum}/{pageSize}")
    @ResponseBody
    public JsonResult findAllGoodsInfoAdmin
    (@PathVariable("pageNum") Integer pageNum,@PathVariable("pageSize") Integer pageSize){
        return adminService.findAllGoodsInfoAdmin(pageNum,pageSize);
    }

    //管理员-商品管理-根据商品id查询商品信息
    @GetMapping("/findGoodsInfoById/{gid}")
    @ResponseBody
    public JsonResult findGoodsInfoByIdAdmin(@PathVariable("gid") Integer gid){
        return adminService.findGoodsInfoByIdAdmin(gid);
    }

    //管理员-商品管理-添加商品
    @PostMapping("/addGoodInfo")
    @ResponseBody
    public JsonResult addGoodInfoAdmin(@RequestBody Goods goods){
        return adminService.addGoodsInfoAdmin(goods);
    }

    //管理员-商品管理-删除商品
    @PostMapping("/deleteGoodsInfo/{gid}")
    @ResponseBody
    public JsonResult deleteGoodsInfoAdmin(@PathVariable("gid") Integer gid){
        return adminService.deleteGoodsInfoAdmin(gid);
    }

    //管理员-商品管理-修改商品信息
    @PostMapping("/updateGoodsInfo")
    @ResponseBody
    public JsonResult updateGoodsInfo(@RequestBody Goods goods){
        return adminService.updateGoodsInfoAdmin(goods);
    }


}
